package com.nowcoder.Offer.Tree;

/**
 * 判断是否是树的子结构
 */
public class HasSubTree {

    public boolean HasSubtree(TreeNode A,TreeNode B) {
        if(A == null || B == null) return false;

        return isSubTree(A,B) || HasSubtree(A.right,B) || HasSubtree(A.left,B);
    }

    public boolean isSubTree(TreeNode A, TreeNode B){
        if(B == null )
            return true;

        if(A == null)
            return false;

        if(A.val != B.val )
            return false;
        //如果 A.val == B.val 则继续往下找
        return isSubTree(A.left,B.left) && isSubTree(A.right, B.right);
    }
}
